package cn.broadmax.boot.modules.aj.bean;

import cn.broadmax.boot.modules.aj.entity.Record;
import cn.broadmax.boot.modules.sys.entity.SysLog;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jexx.util.StringUtil;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@Data
@ApiModel(value="ajRecord分页查询请求", description="ajRecord分页查询")
public class ajRecordPageSearch {

    @ApiModelProperty(value = "案卷名称")
    private String name;

    @ApiModelProperty(value = "案卷编号")
    private String code;

    @ApiModelProperty(value = "开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startLogTime;

    @ApiModelProperty(value = "结束时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endLogTime;

    public static LambdaQueryWrapper<Record> createWrap(ajRecordPageSearch search){
        LambdaQueryWrapper<Record> wrapper = new LambdaQueryWrapper<>();
        if(search != null){
            if(StringUtil.hasText(search.getName())){
                wrapper.like(Record::getName, search.getName());
            }
            if(StringUtil.hasText(search.getCode())){
                wrapper.like(Record::getCode, search.getCode());
            }
            if(search.getStartLogTime() != null && search.getEndLogTime() != null){
                wrapper.between(Record::getCreateTime, search.getStartLogTime(), search.getEndLogTime());
            }
            else if(search.getStartLogTime() != null ){
                wrapper.ge(Record::getCreateTime, search.getStartLogTime());
            }
            else if(search.getEndLogTime() != null){
                wrapper.le(Record::getCreateTime, search.getEndLogTime());
            }
        }
        wrapper.orderByDesc(Record::getCreateTime);
        return wrapper;
    }

}
